package com.qf.service.impl;

import com.qf.entity.Answers;
import com.qf.entity.Questions;
import com.qf.mapper.AnswersMapper;
import com.qf.service.AnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lenovo
 * @version V1.0
 * @Date 2021/10/6 2:42
 */
@Service
public class AnswersServiceImpl implements AnswersService {

    @Autowired
    private AnswersMapper answersMapper;

    @Override
    public List<Answers> findAllByQues(Questions questions) {
        return answersMapper.findAllByQues(questions);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void add(Answers answers) {
        int i = answersMapper.insert(answers);
        if (i != 1){
            System.out.println("添加失败");
            throw new RuntimeException("添加失败");
        }
    }
}
